import Home from '../pages/home';
import Login from '../pages/login';
import AssessManege from '../pages/assessManege';
import BillManege from '../pages/billManege/index';
import CarefulManManege from '../pages/carefulManManege';
import DeviceManege from '../pages/deviceManege';
import HeathManege from '../pages/heathManege';
import OldManManege from '../pages/oldManManege';
import OrderManege from '../pages/orderManege';
import RefundManege from '../pages/refundManege';
import ServiceClass from '../pages/serviceClass';
import SystemManege from '../pages/systemManege';
import { Switch, Route, Redirect } from 'react-router-dom';
import React from 'react';

function Routes() {
    
    const routeArr = [
        {
            path: '/home',
            component: Home,
            name: '首页',
            children: [
                {
                    path: '/home/assessManege',
                    component: AssessManege,
                    name: '评价管理'
                },

                {
                    path: '/home/billManege',
                    component: BillManege,
                    name: '对账管理'
                },
                {
                    path: '/home/carefulManManege',
                    component: CarefulManManege,
                    name: '陪护员管理'
                },
                {
                    path: '/home/deviceManege',
                    component: DeviceManege,
                    name: '设备管理'
                },
                {
                    path: '/home/heathManege',
                    component: HeathManege,
                    name: '健康管理'
                },
                {
                    path: '/home/oldManManege',
                    component: OldManManege,
                    name: '老人管理'
                },
                {
                    path: '/home/orderManege',
                    component: OrderManege,
                    name: '订单管理'
                },
                {
                    path: '/home/refundManege',
                    component: RefundManege,
                    name: '退款管理'
                },
                {
                    path: '/home/serviceClass',
                    component: ServiceClass,
                    name: '服务类型'
                },
                {
                    path: '/home/systemManege',
                    component: SystemManege,
                    name: '系统管理'
                }

            ]
        },
        {
            path: '/login',
            component: Login,
            name: '登录',
            children: []
        }
    ];
    return (
        // <BrowserRouter>
        <Switch>
            <Route exact path="/home"><Home /></Route>
            {
                routeArr.map((item, index) => {
                    if (item.children.length) {
                        return item.children.map((item2, index2) => {
                            // return <Route key={index2} path={item2.path}>{item2.component}</Route>
                            return <Route key={index2} path={item2.path} component={item2.component}/>
                        })
                    } 
                    // else {
                    //     return <Route key={index} path={item.path}>{item.component}</Route>
                    // }
                })
            }
            <Redirect to="/home"><Home /></Redirect>
        </Switch>
        // </BrowserRouter>
    )
}

export default Routes;
